<admintpl file="header"/>

<link rel="stylesheet" href="__PUBLIC__/css/main.css">
<link rel="stylesheet" href="__PUBLIC__/css/act_info.css">
<script src="__PUBLIC__/js/uploadify/jquery2.js" type="text/javascript"></script>
<script src="__PUBLIC__/js/uploadify/jquery.uploadify.min.js" type="text/javascript"></script>
<script src="__PUBLIC__/js/jquery.form.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="__PUBLIC__/js/uploadify/uploadify.css">

<link rel="stylesheet" href="__PUBLIC__/css/jquery.datetimepicker.css">
<script src="__PUBLIC__/js/laydate.js"></script>

<style type="text/css">
    .hidden {
        display: none;
    }
</style>
</head>
<body>

<div class="manage">
    <span><a href="{:U('Package/index')}">运营管理</a></span>
</div>

<div class="act_main"><a href="{:U('Package/index')}">运营工具</a>
        <span class="act-nav">
                <a href="{:U('shortlink/index')}">短链接管理</a>

        </span>
</div>

<div class="wrap">
    <div class="form-horizontal Jactadd">
        <div class="control-group">
            <label class="control-label act-info"></label>

            <div class="controls act_right text-center">
                <ul>
                    <li><a href="{:U('shortlink/index')}">> <span>返回短链接管理</span></a></li>
                </ul>
            </div>
        </div>

        <div method="post" id="formSubmit" class="form-horizontal">

            <div class="control-group">
                <label class="control-label "></label>
                <div class="controls">
                    <input type="radio" name='url' value="1" checked>web链接地址  &nbsp;&nbsp;&nbsp;&nbsp;
                    <input type="radio" name='url' value="2">APP链接地址
                    <span class="form-required">*</span>
                </div>
            </div>

            <div class="control-group">
                <label class="control-label ">链接名称：</label>

                <div class="controls">
                    <input type="text" name="title" placeholder="请输入名称" maxlength="20">
                    <span class="form-required">*</span>
                </div>
            </div>

            <div class="control-group">
                <label class="control-label ">链接地址：</label>

                <div class="controls">
                    <input type="text" name="longUrl" class="longUrl" placeholder="请输入链接地址" maxlength="250">
                    <span class="form-required">*</span>
                </div>
            </div>

            <div class="control-group">
                <label class="control-label ">APP链接地址：</label>

                <div class="controls">
                    <input type="text" name="appUrl" class="appUrl" placeholder="请输入APP链接地址" maxlength="250" disabled>
                    <span class="form-required">*</span>
                </div>
            </div>

            <div class="control-group">
                <label class="control-label "></label>

                <div class="controls">
                    <button id="saveBtn" type="submit" class="btn btn-primary">提交</button>
                    <span class="form-required"></span>
                </div>
            </div>
        </div>
    </div>
</div>


<script type="text/javascript">
    $(function () {
        $('input:radio[name=url]').change(function(){
            var checkUrl = $(this).val();
            console.log(checkUrl);
            if(checkUrl==1){
                $('.longUrl').removeAttr('disabled');
                $('.appUrl').attr('disabled',true);
            }else{
                $('.longUrl').attr('disabled',true);
                $('.appUrl').removeAttr('disabled');
            }

        })

        $('#saveBtn').on('click', function() {
            var checkValue = $("input[type='radio']:checked").val();
            $.ajax({
                url:"{:U('shortlink/add')}",
                type:"post",
                data:{
                    title:$('[name="title"]').val(),
                    longUrl: checkValue==1 ? $('[name="longUrl"]').val() : $('[name="appUrl"]').val(),
                    checkValue:checkValue
                },
                dataType:"json",
                success : function(data) {
                    if(data.status == 0) {
                        //alert('添加成功');
                        location.href="{:U('shortlink/view')}&id=" + data.data.newId;
                    } else {
                        alert(data.msg);
                    }
                }
            });
        });
    });
</script>
</body>
</html>